package com.gopay.scheduler.mq;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.support.converter.MessageConverter;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

/**
 * 队列消息监听
 */
public class QueueMessageListener implements MessageListener {
    private static Logger logger = LoggerFactory.getLogger(QueueMessageListener.class);

    /**
     * 接收消息
     */
    @Override
    public void onMessage(Message message) {
        try {
            if (message instanceof ObjectMessage) {
                logger.info("收到对象消息：{}",message);
            } else if (message instanceof TextMessage) {
                TextMessage txt = (TextMessage) message;
                logger.info("收到文本消息：{}",txt);
            }
        } catch (Exception e) {
            logger.error("处理信息时发生异常", e);
            throw new RuntimeException(e.getMessage());
        }
    }
}